<?php
// echo "b";
// var_dump($_SESSION);
// exit;
/*没有登录的跳转到sso网站*/
$_GET['session_id'] && session_id($_GET['session_id']);
session_start();

if($_GET['act'] == 'logout'){
	$_SESSION = null;
	echo "logout";
	exit;
}
if (empty($_SESSION)) {

	if(!isset($_GET['session_id'])){
		$redirect = "http://192.168.103.215:10081/?";
	    $url = "http://192.168.103.215:10080/?act=login&redirect="; //
	    header ( 'Location: ' . $url );
	    exit;
	}else{
		$session_id = $_GET['session_id'];
		var_dump($session_id);
	}
	echo "<br/>";

    $context = stream_context_create(array(
        'http' => array(
            'timeout' => 30,
        ),
    )); // 超时时间，单位为秒

    $url = "http://192.168.103.215:10080/?act=sso&session_id=".$session_id;
    echo $url,"<br/>";
    $res = file_get_contents($url, 0, $context);
    echo "sso:";
    echo $res;
    if ($res) {
        $res = json_decode($res, true);
    }
    var_dump($res);
    if ($res && $res['status'] == 200 && $res['data']) {
        $_SESSION = $res['data'];

       	$url = "/"; //
	    header ( 'Location: ' . $url );
	    exit;
    }else{
    	$_SESSION = null;
    }
}else{
	print_r($_SESSION);
}


